// js/pages/LeaderboardPage.js
import BasePage from './BasePage.js';
import TextRenderer from '../utils/TextRenderer.js';
import myFn from '../utils/myFn.js';

// 提取常量
const UI_CONSTANTS = {
  COLORS: {
    HEADER_TEXT: '#6EACD9',
    TITLE_TEXT: '#8A98CC',
    WHITE: '#ffffff',
    GOLD: '#FFD700',
    SELECTED: '#EBCC4F',
    WIN_RATE_HIGH: '#4CAF50',
    WIN_RATE_MEDIUM: '#FFC107',
    WIN_RATE_LOW: '#F44336'
  },
  SIZES: {
    HEADER_HEIGHT: 74,
    ITEM_HEIGHT: 74,
    ITEM_SPACING: 10,
    LIST_PADDING: 16, // 列表左右边距
    LIST_BOTTOM_MARGIN: 10 // 列表下边距
  },
  POSITIONS: {
    BACK_BUTTON: { X: 78, Y: 28, WIDTH: 28, HEIGHT: 42 },
    TITLE: { Y: 30 },
    MENU: {
      RANKING: { X: 42, Y: 138, WIDTH: 106, HEIGHT: 108, TEXT_Y: 300 },
      CHALLENGE: { X: 52, Y: 364, WIDTH: 96, HEIGHT: 88, TEXT_Y: 510 }
    },
    LIST: { X: 192, Y: 104, WIDTH: 1006, HEIGHT: 636 }, // 恢复原始坐标
    AVATAR: { X: 1242, Y: 220, WIDTH: 112, HEIGHT: 112 },
    USER_INFO: {
      TITLE: { X: 1226, Y: 150 },
      NAME: { X: 1568, Y: 288 },
      RANKING_LABEL: { X: 1262, Y: 398 },
      RANKING_VALUE: { X: 1568, Y: 394 },
      BALANCE_LABEL: { X: 1262, Y: 494 },
      BALANCE_VALUE: { X: 1568, Y: 494 },
      INVEST_LABEL: { X: 1262, Y: 554 },
      INVEST_VALUE: { X: 1568, Y: 554 },
      WIN_RATE_LABEL: { X: 1262, Y: 614 },
      WIN_RATE_VALUE: { X: 1568, Y: 614 }
    }
  },
  FONT_SIZES: {
    TITLE: 52,
    MENU: 32,
    HEADER: 28,
    USER_INFO: 28,
    RANKING_VALUE: 68
  },
  SCROLL: {
    FRICTION: 0.95,
    MIN_VELOCITY: 10,
    LOAD_THRESHOLD: 0.7,
    ANIMATION_FRAME: 0.016
  }
};

// 排名渐变配置
const RANKING_GRADIENTS = {
  0: { // 第一名
    colors: ['#BFB998', '#47485E', '#3E335B']
  },
  1: { // 第二名
    colors: ['#7D86A7', '#3C3F60', '#3E335B']
  },
  2: { // 第三名
    colors: ['#937E85', '#413E5B', '#3E335B']
  },
  default: { // 其他排名
    colors: ['#33446F', '#3E335B']
  }
};

export default class LeaderboardPage extends BasePage {
  constructor(canvas, ctx, pageManager, resourceManager, screenAdapter, api, userManager) {
    super(canvas, ctx, pageManager, resourceManager, screenAdapter);
    this.api = api;
    this.userManager = userManager;
    this.textRenderer = new TextRenderer(ctx, screenAdapter);
    
    // 页面状态
    this.pageState = {
      selectedMenuIndex: 1,
      isLoading: false,
      hasMore: true,
      isInitialized: false
    };
    
    // 列表配置
    this.listConfig = {
      scaleRatio: 1,
      headers: ['排名', '姓名', '资金', '投资次数', '胜率'],
      pageSize: 20,
      currentPage: 1
    };
    
    // 滚动状态
    this.scrollState = {
      data: [],
      rankingList: [],
      visibleStart: 0,
      visibleEnd: 0,
      scrollTop: 0,
      maxScrollTop: 0,
      touchStartY: 0,
      touchStartTime: 0,
      lastTouchY: 0,
      velocityY: 0,
      isScrolling: false,
      animationId: null
    };
    
    // 用户数据
    this.userData = {
      userBattle: null
    };
  }

  onInit() {
    return Promise.resolve();
  }

  /**
   * 页面初始化方法
   */
  async initialize() {
    try {
      await this.initializeUI();
      await this.loadInitialData();
      this.pageState.isInitialized = true;
    } catch (error) {
      console.error('排行榜页面初始化失败:', error);
      throw error;
    }
  }

  /**
   * 初始化UI
   */
  async initializeUI() {
    this.calculateListDimensions();
  }

  /**
   * 计算列表尺寸
   */
  calculateListDimensions() {
    const ratio = this.listConfig.scaleRatio;
    this.listDimensions = {
      x: UI_CONSTANTS.POSITIONS.LIST.X * ratio,
      y: UI_CONSTANTS.POSITIONS.LIST.Y * ratio,
      width: UI_CONSTANTS.POSITIONS.LIST.WIDTH * ratio,
      height: UI_CONSTANTS.POSITIONS.LIST.HEIGHT * ratio,
      headerHeight: UI_CONSTANTS.SIZES.HEADER_HEIGHT * ratio,
      itemHeight: UI_CONSTANTS.SIZES.ITEM_HEIGHT * ratio,
      itemSpacing: UI_CONSTANTS.SIZES.ITEM_SPACING * ratio,
      padding: UI_CONSTANTS.SIZES.LIST_PADDING * ratio,
      bottomMargin: UI_CONSTANTS.SIZES.LIST_BOTTOM_MARGIN * ratio
    };
  }

  /**
   * 加载初始数据
   */
  async loadInitialData() {
    try {
      await Promise.all([
        this.loadUserStatistics(),
        this.loadRankingData()
      ]);
      this.updateVisibleRange();
    } catch (error) {
      console.error('加载初始数据失败:', error);
      myFn.showToast('加载数据失败，请重试');
    }
  }

  /**
   * 加载用户统计数据
   */
  async loadUserStatistics() {
    try {
      const response = await this.api.game.getstatistic();
      this.userData.userBattle = response.data;
    } catch (error) {
      console.error('获取用户统计失败:', error);
      throw error;
    }
  }

  /**
   * 加载排行榜数据
   */
  async loadRankingData() {
    try {
      const response = await this.api.game.getranking();
      this.scrollState.data = response.data || [];
    } catch (error) {
      console.error('获取排行榜数据失败:', error);
      throw error;
    }
  }

  /**
   * 渲染页面
   */
  render() {
    if (!this.pageState.isInitialized) return;

    this.renderBackground();
    this.renderHeader();
    this.renderMenu();
    this.renderUserInfo();
    this.renderRankingList();
  }

  /**
   * 渲染背景
   */
  renderBackground() {
    const rankingBg = this.resourceManager.getImage('rankingBg');
    if (rankingBg) {
      this.ctx.drawImage(rankingBg, 0, 0, this.screenAdapter.DESIGN_WIDTH, this.screenAdapter.DESIGN_HEIGHT);
    }
  }

  /**
   * 渲染顶部标题栏
   */
  renderHeader() {
    // 返回按钮
    const backIcon = this.resourceManager.getImage('backIcon');
    if (backIcon) {
      this.ctx.drawImage(backIcon, UI_CONSTANTS.POSITIONS.BACK_BUTTON.X, UI_CONSTANTS.POSITIONS.BACK_BUTTON.Y, 
                          UI_CONSTANTS.POSITIONS.BACK_BUTTON.WIDTH, UI_CONSTANTS.POSITIONS.BACK_BUTTON.HEIGHT);
    }

    // 标题
    this.textRenderer.drawText('排行榜', this.screenAdapter.DESIGN_WIDTH / 2, UI_CONSTANTS.POSITIONS.TITLE.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.TITLE}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.TITLE_TEXT, 'center', 'top');
  }

  /**
   * 渲染左侧菜单
   */
  renderMenu() {
    // 排位赛按钮
    this.renderMenuItem(UI_CONSTANTS.POSITIONS.MENU.RANKING, 'rankingIcon', 'rankingIconSelect', 
                       '排位赛', 1);

    // 挑战赛按钮
    this.renderMenuItem(UI_CONSTANTS.POSITIONS.MENU.CHALLENGE, 'challengeIcon', 'challengeIconSelect', 
                       '挑战赛', 2);
  }

  /**
   * 渲染菜单项
   */
  renderMenuItem(position, normalIconKey, selectedIconKey, text, menuIndex) {
    const isSelected = this.pageState.selectedMenuIndex === menuIndex;
    const iconKey = isSelected ? selectedIconKey : normalIconKey;
    const icon = this.resourceManager.getImage(iconKey);
    
    if (icon) {
      this.ctx.drawImage(icon, position.X, position.Y, position.WIDTH, position.HEIGHT);
    }

    this.textRenderer.drawText(text, position.X + position.WIDTH / 2, position.TEXT_Y, 
                               `${UI_CONSTANTS.FONT_SIZES.MENU}px ${this.textRenderer.systemFont}`, 
                               isSelected ? UI_CONSTANTS.COLORS.SELECTED : UI_CONSTANTS.COLORS.WHITE, 
                               'center', 'top');
  }

  /**
   * 渲染用户信息
   */
  renderUserInfo() {
    if (!this.userData.userBattle) return;

    // 头像
    const defaultAvatar = this.resourceManager.getImage('defaultAvatar');
    if (defaultAvatar) {
      this.ctx.drawImage(defaultAvatar, UI_CONSTANTS.POSITIONS.AVATAR.X, UI_CONSTANTS.POSITIONS.AVATAR.Y, 
                          UI_CONSTANTS.POSITIONS.AVATAR.WIDTH, UI_CONSTANTS.POSITIONS.AVATAR.HEIGHT);
    }

    const userBattle = this.userData.userBattle;
    const positions = UI_CONSTANTS.POSITIONS.USER_INFO;

    // 用户信息文本
    this.textRenderer.drawText('我的排名', positions.TITLE.X, positions.TITLE.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'left', 'top');

    this.textRenderer.drawText('天心区巴菲特', positions.NAME.X, positions.NAME.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'right', 'top');

    this.textRenderer.drawText('排名：', positions.RANKING_LABEL.X, positions.RANKING_LABEL.Y, 
                               `bold ${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'left', 'top');

    this.textRenderer.drawText(userBattle.ranking, positions.RANKING_VALUE.X, positions.RANKING_VALUE.Y, 
                               `bold ${UI_CONSTANTS.FONT_SIZES.RANKING_VALUE}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'right', 'top');

    this.textRenderer.drawText('资金：', positions.BALANCE_LABEL.X, positions.BALANCE_LABEL.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'left', 'top');

    this.textRenderer.drawText(myFn.formatNumberManually(userBattle.balance), positions.BALANCE_VALUE.X, positions.BALANCE_VALUE.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'right', 'top');

    this.textRenderer.drawText('投资次数：', positions.INVEST_LABEL.X, positions.INVEST_LABEL.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'left', 'top');

    this.textRenderer.drawText(userBattle.investment_num, positions.INVEST_VALUE.X, positions.INVEST_VALUE.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'right', 'top');

    this.textRenderer.drawText('胜率：', positions.WIN_RATE_LABEL.X, positions.WIN_RATE_LABEL.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'left', 'top');

    const winRate = myFn.calculateIntegerPercentage(userBattle.profit_num, userBattle.investment_num);
    this.textRenderer.drawText(winRate, positions.WIN_RATE_VALUE.X, positions.WIN_RATE_VALUE.Y, 
                               `${UI_CONSTANTS.FONT_SIZES.USER_INFO}px ${this.textRenderer.systemFont}`, 
                               UI_CONSTANTS.COLORS.WHITE, 'right', 'top');
  }

  /**
   * 渲染排行榜列表
   */
  renderRankingList() {
    this.renderTableHeader();
    this.renderTableContent();
  }

  /**
   * 渲染表头
   */
  renderTableHeader() {
    const { x, y, width, headerHeight, padding } = this.listDimensions;
    const contentWidth = width - padding * 2; // 减去左右边距
    const columnWidth = contentWidth / this.listConfig.headers.length;
    const startX = x + padding; // 从左边距开始

    this.listConfig.headers.forEach((header, index) => {
      const centerX = startX + columnWidth * index + columnWidth / 2;
      const centerY = y + headerHeight / 2;
      
      this.textRenderer.drawText(header, centerX, centerY, 
                                 `${UI_CONSTANTS.FONT_SIZES.HEADER}px ${this.textRenderer.systemFont}`, 
                                 UI_CONSTANTS.COLORS.HEADER_TEXT, 'center', 'middle');
    });
  }

  /**
   * 渲染表格内容
   */
  renderTableContent() {
    const { x, y, width, height, headerHeight } = this.listDimensions;

    // 设置裁剪区域
    this.ctx.save();
    this.ctx.beginPath();
    this.ctx.rect(x, y + headerHeight, width, height - headerHeight);
    this.ctx.clip();

    // 绘制可见列表项
    this.drawVisibleItems();

    // 恢复裁剪区域
    this.ctx.restore();
  }

  /**
   * 绘制可见列表项
   */
  drawVisibleItems() {
    const { data, visibleStart, visibleEnd } = this.scrollState;
    const { x, y, headerHeight, itemHeight, itemSpacing, padding, width } = this.listDimensions;
    
    const itemTotalHeight = itemHeight + itemSpacing;
    const startY = y + headerHeight;

    for (let i = visibleStart; i <= visibleEnd; i++) {
      if (i >= data.length) break;

      const item = data[i];
      const itemY = startY + i * itemTotalHeight - this.scrollState.scrollTop;

      // 只绘制在可视区域内的项目
      if (itemY + itemHeight < y || itemY > y + headerHeight + (this.listDimensions.height - headerHeight)) {
        continue;
      }

      this.drawRankingItem(item, itemY, i);
    }
  }

  /**
   * 绘制排名项
   */
  drawRankingItem(item, y, index) {
    const { x, y: listY, width, headerHeight, itemHeight, padding } = this.listDimensions;
    const itemX = x + padding; // 从左边距开始
    const itemWidth = width - padding * 2; // 减去左右边距

    // 绘制背景
    this.drawItemBackground(itemX, y, itemWidth, itemHeight, index);

    // 绘制文本内容
    this.drawItemContent(item, y, index, itemX, itemWidth);
  }

  /**
   * 绘制项目背景
   */
  drawItemBackground(x, y, width, height, index) {
    const gradient = this.ctx.createLinearGradient(x, 0, x + width, 0);
    const gradientConfig = RANKING_GRADIENTS[index] || RANKING_GRADIENTS.default;
    
    gradientConfig.colors.forEach((color, stopIndex) => {
      gradient.addColorStop(stopIndex / (gradientConfig.colors.length - 1), color);
    });

    this.ctx.fillStyle = gradient;
    this.ctx.fillRect(x, y, width, height);
  }

  /**
   * 绘制项目内容
   */
  drawItemContent(item, y, index, x, width) {
    const columnWidth = width / this.listConfig.headers.length;
    const values = [item.ranking, item.user_name, item.balance, item.all_count, item.win_rate];

    values.forEach((value, colIndex) => {
      const centerX = x + columnWidth * colIndex + columnWidth / 2;
      const centerY = y + this.listDimensions.itemHeight / 2;

      this.drawItemValue(value, colIndex, index, centerX, centerY);
    });
  }

  /**
   * 绘制项目值
   */
  drawItemValue(value, colIndex, index, x, y) {
    let font = `${UI_CONSTANTS.FONT_SIZES.HEADER}px ${this.textRenderer.systemFont}`;
    let color = UI_CONSTANTS.COLORS.WHITE;

    switch (colIndex) {
      case 0: // 排名
        font = `bold ${UI_CONSTANTS.FONT_SIZES.HEADER}px ${this.textRenderer.systemFont}`;
        color = index < 3 ? UI_CONSTANTS.COLORS.GOLD : UI_CONSTANTS.COLORS.WHITE;
        break;
      case 4: // 胜率
        font = `bold ${UI_CONSTANTS.FONT_SIZES.HEADER}px ${this.textRenderer.systemFont}`;
        const winRate = parseFloat(value) || 0;
        color = winRate > 60 ? UI_CONSTANTS.COLORS.WIN_RATE_HIGH : 
                winRate > 40 ? UI_CONSTANTS.COLORS.WIN_RATE_MEDIUM : 
                UI_CONSTANTS.COLORS.WIN_RATE_LOW;
        value = winRate + "%";
        break;
    }

    this.textRenderer.drawText(value, x, y, font, color, 'center', 'middle');
  }

  /**
   * 处理触摸开始事件
   */
  handleTouchStart(event) {
    const touch = event.touches[0];
    const logicPoint = this.screenAdapter.screenToLogic(touch.clientX, touch.clientY);

    // 检查是否在列表区域
    if (this.isInListArea(logicPoint)) {
      this.startScrolling(touch.clientY);
    }
  }

  /**
   * 处理触摸结束事件
   */
  handleTouchEnd(event) {
    const touch = event.changedTouches[0];
    const logicPoint = this.screenAdapter.screenToLogic(touch.clientX, touch.clientY);

    // 处理按钮点击
    if (this.handleButtonClick(logicPoint)) {
      return;
    }

    // 结束滚动
    if (this.scrollState.isScrolling) {
      this.endScrolling();
    }
  }

  /**
   * 处理触摸移动事件
   */
  handleTouchMove(event) {
    if (!this.scrollState.isScrolling) return;

    const touch = event.touches[0];
    const deltaY = this.scrollState.lastTouchY - touch.clientY;

    this.updateScrollVelocity(deltaY);
    this.handleScroll(deltaY);

    this.scrollState.lastTouchY = touch.clientY;
    this.scrollState.touchStartTime = Date.now();
  }

  /**
   * 检查是否在列表区域
   */
  isInListArea(point) {
    const { x, y, width, height } = this.listDimensions;
    return point.x >= x && point.x <= x + width && 
           point.y >= y && point.y <= y + height;
  }

  /**
   * 开始滚动
   */
  startScrolling(y) {
    this.scrollState.touchStartY = y;
    this.scrollState.lastTouchY = y;
    this.scrollState.touchStartTime = Date.now();
    this.scrollState.velocityY = 0;
    this.scrollState.isScrolling = true;

    // 停止惯性滚动
    if (this.scrollState.animationId) {
      cancelAnimationFrame(this.scrollState.animationId);
      this.scrollState.animationId = null;
    }
  }

  /**
   * 结束滚动
   */
  endScrolling() {
    this.scrollState.isScrolling = false;
    this.startInertiaScroll();
  }

  /**
   * 更新滚动速度
   */
  updateScrollVelocity(deltaY) {
    const currentTime = Date.now();
    const timeDelta = currentTime - this.scrollState.touchStartTime;
    
    if (timeDelta > 0) {
      this.scrollState.velocityY = deltaY / timeDelta * 1000;
    }
  }

  /**
   * 处理滚动
   */
  handleScroll(deltaY) {
    const newScrollTop = Math.max(0, Math.min(this.scrollState.maxScrollTop, this.scrollState.scrollTop + deltaY));

    if (newScrollTop !== this.scrollState.scrollTop) {
      this.scrollState.scrollTop = newScrollTop;
      this.updateVisibleRange();

      // 检查是否需要加载更多数据
      if (this.shouldLoadMore()) {
        this.loadMoreData();
      }
    }
  }

  /**
   * 开始惯性滚动
   */
  startInertiaScroll() {
    const animate = () => {
      if (Math.abs(this.scrollState.velocityY) < UI_CONSTANTS.SCROLL.MIN_VELOCITY) {
        this.scrollState.animationId = null;
        return;
      }

      const deltaY = this.scrollState.velocityY * UI_CONSTANTS.SCROLL.ANIMATION_FRAME;
      this.handleScroll(deltaY);

      this.scrollState.velocityY *= UI_CONSTANTS.SCROLL.FRICTION;
      this.scrollState.animationId = requestAnimationFrame(animate);
    };

    animate();
  }

  /**
   * 处理按钮点击
   */
  handleButtonClick(point) {
    // 返回按钮
    if (this.isBackButtonClicked(point)) {
      this.pageManager.showPage('home');
      return true;
    }

    // 菜单按钮
    if (this.isMenuButtonClicked(point)) {
      return true;
    }

    return false;
  }

  /**
   * 检查返回按钮是否被点击
   */
  isBackButtonClicked(point) {
    const btn = UI_CONSTANTS.POSITIONS.BACK_BUTTON;
    return point.x >= btn.X && point.x <= btn.X + btn.WIDTH && 
           point.y >= btn.Y && point.y <= btn.Y + btn.HEIGHT;
  }

  /**
   * 检查菜单按钮是否被点击
   */
  isMenuButtonClicked(point) {
    if (point.x < 20 || point.x > 172) return false;

    // 挑战赛按钮
    if (point.y >= 320 && point.y <= 500) {
      myFn.showToast('暂未开启挑战赛');
      return true;
    }

    return false;
  }

  /**
   * 更新可见范围
   */
  updateVisibleRange() {
    const { data } = this.scrollState;
    const { height, headerHeight, itemHeight, itemSpacing, bottomMargin } = this.listDimensions;
    
    // 计算内容高度，考虑下边距
    const contentHeight = data.length * (itemHeight + itemSpacing) + bottomMargin;
    this.scrollState.maxScrollTop = Math.max(0, contentHeight - (height - headerHeight));

    const visibleHeight = height - headerHeight;
    const itemTotalHeight = itemHeight + itemSpacing;

    this.scrollState.visibleStart = Math.floor(this.scrollState.scrollTop / itemTotalHeight);
    this.scrollState.visibleEnd = Math.min(
      data.length - 1,
      Math.ceil((this.scrollState.scrollTop + visibleHeight) / itemTotalHeight)
    );
  }

  /**
   * 检查是否需要加载更多数据
   */
  shouldLoadMore() {
    if (this.scrollState.maxScrollTop <= 0) return false;
    
    const scrollPercent = this.scrollState.scrollTop / this.scrollState.maxScrollTop;
    return scrollPercent > UI_CONSTANTS.SCROLL.LOAD_THRESHOLD && 
           !this.pageState.isLoading && 
           this.pageState.hasMore;
  }

  /**
   * 加载更多数据
   */
  async loadMoreData() {
    if (this.pageState.isLoading || !this.pageState.hasMore) return;

    this.pageState.isLoading = true;

    try {
      this.listConfig.currentPage++;
      const newData = await this.fetchRankingData(this.listConfig.currentPage);

      if (newData.length < this.listConfig.pageSize) {
        this.pageState.hasMore = false;
      }

      this.scrollState.data = [...this.scrollState.data, ...newData];
      this.updateVisibleRange();
    } catch (error) {
      console.error('加载更多数据失败:', error);
      myFn.showToast('加载更多数据失败');
    } finally {
      this.pageState.isLoading = false;
    }
  }

  /**
   * 获取排行榜数据
   */
  async fetchRankingData(page) {
    // 这里应该调用实际的API
    // 暂时返回模拟数据
    return new Promise((resolve) => {
      setTimeout(() => {
        const mockData = [];
        const start = (page - 1) * this.listConfig.pageSize;

        for (let i = 0; i < this.listConfig.pageSize; i++) {
          const index = start + i + 1;
          mockData.push({
            ranking: index,
            user_name: `用户${index}`,
            balance: (Math.random() * 1000000 + 100000).toFixed(2),
            all_count: Math.floor(Math.random() * 100) + 1,
            win_rate: (Math.random() * 100).toFixed(2)
          });
        }

        resolve(mockData);
      }, 300);
    });
  }
}
